﻿/* ######################################## *\
 * ### Copyright (C) 2009 AJ Ravindiran ### *
\* ######################################## */
using System;
using System.Data;

using AJRavindiran.Jolt.Storage;
using AJRavindiran.Jolt.RuneScape.Models.Characters;
using AJRavindiran.Jolt.Utilities;

namespace AJRavindiran.Jolt.RuneScape.Database.Characters
{
    /// <summary>
    /// Represents a character saver.
    /// </summary>
    public class AccountSaver
    {
        /// <summary>
        /// Runs a execute sequence to save a player's character.
        /// </summary>
        /// <param name="character"></param>
        public void Execute(Character character)
        {
            DataRow dataRow;
            using (DatabaseClient dbClient = Jolt.GetDatabase().GetClient())
            {
                dbClient.AddParamWithValue("username", StringUtilities.FormatForProtocol(character.GetDetails().Username));
                dataRow = dbClient.ReadDataRow("SELECT id FROM users WHERE username = @username LIMIT 1");
            }

            try
            {
                if (dataRow.Table.Rows.Count > 0)
                {
                    // If there is a record of this player in the database, we will save the current cahracter values.
                    using (DatabaseClient dbclient = Jolt.GetDatabase().GetClient())
                    {
                        // CODE
                    }
                }
                else
                {
                    // If tehre is no record, we will create one and save the current character values.
                    using (DatabaseClient dbclient = Jolt.GetDatabase().GetClient())
                    {
                        // CODE
                    }
                }
            }
            catch (Exception ex)
            {
                Jolt.GetLog().WriteException(ex);
            }
        }
    }
}
